package com.qianbei.common.view;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.qianbei.R;

/**
 * 确认完成订单
 *
 * @author gml
 */
@SuppressLint("NewApi")
public class CloseAQDialog extends DialogFragment implements OnClickListener {


    private String mTitle, mCancel, mOk;

    private TextView continu_but, complete_close, complete_but;

    public static CloseAQDialog newInstance(String title, String cancel, String ok) {
        CloseAQDialog f = new CloseAQDialog();

        // Supply num input as an argument.
        Bundle args = new Bundle();
        args.putString("title", title);
        args.putString("cancel", cancel);
        args.putString("ok", ok);
        f.setArguments(args);
        return f;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black);
//				Theme_Black_NoTitleBar_Fullscreen);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.complet_dialog_fragment,
                container);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        complete_close = (TextView) view.findViewById(R.id.complete_close);

        complete_close.setOnClickListener(this);
        continu_but = (TextView) view.findViewById(R.id.continu_but);
        continu_but.setOnClickListener(this);
        complete_but = (TextView) view.findViewById(R.id.complete_but);
        complete_but.setOnClickListener(this);
        view.findViewById(R.id.out_view).setOnClickListener(this);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mTitle = getArguments().getString("title");
        mCancel = getArguments().getString("cancel");
        mOk = getArguments().getString("ok");
//        if (!TextUtils.isEmpty(mTag)) {
//            continu_but.setText("取消");
//            complete_close.setText("是否要关闭问答？");
//        }
        continu_but.setText(mCancel);
        complete_close.setText(mTitle);

        complete_but.setText(mOk);

    }

    public DialogClick click;

    public interface DialogClick {
        // 点击试图的 id 最后传递给 实现者 baseActivity
        public void dilogClick(int id);
    }

    @Override
    public void onClick(View arg0) {
        this.dismiss();


        switch (arg0.getId()) {
            case R.id.complete_but:
                if (click != null) {
                    click.dilogClick(arg0.getId());
                }
                break;
            case R.id.continu_but:
                if (click != null) {
                    click.dilogClick(arg0.getId());
                }
                break;
            case R.id.complete_close:
                if (click != null) {
                    click.dilogClick(arg0.getId());
                }
                break;
            default:
                break;
        }

    }


}
